﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MedicalLog.Domain.Entities;

namespace MedicalLog.Domain.Repositories
{
    public class TestListRepository
    {
        MedicalLogEntities _dbMedicalLog;

        public TestListRepository()
        {
            _dbMedicalLog = new MedicalLogEntities();
        }

        public void AddTestList(TestList testList)
        {
            _dbMedicalLog.TestLists.AddObject(testList);
            _dbMedicalLog.SaveChanges();
        }

        public TestList DeleteTestList(int id)
        {
            try
            {
                return _dbMedicalLog.TestLists.First(x => x.Id == id);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void DeleteTestList(TestList testList)
        {
            _dbMedicalLog.TestLists.DeleteObject(testList);
            _dbMedicalLog.SaveChanges();
        }

        public TestList getTest(string name)
        {
            return _dbMedicalLog.TestLists.First(x => x.TestName == name);
        }

        public TestList getTest(int id)
        {
            return _dbMedicalLog.TestLists.First(x => x.Id == id);
        }

        public IQueryable<TestList> getTests()
        {
            return _dbMedicalLog.TestLists.Select(x => x);
        }
    }
}
